home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / FIG.TRM < prev    next >
Text File  |  1992-03-25  |  8KB  |  278 lines

  1. /*
  2.  * $Id: fig.trm,v 3.26 92/03/24 22:34:53 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - fig.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *  Fig graphics language
  25.  *
  26.  * AUTHORS
  27.  *  Micah Beck, David Kotz
  28.  *
  29.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  30.  *
  31.  */
  32.  
  33. #ifdef MSDOS
  34. #define long int
  35. #endif /* MSDOS */
  36.  
  37. /*
  38.  * Original for Fig code output by Micah Beck, 1989
  39.  * Department of Computer Science, Cornell University
  40.  * Updated by David Kotz for gnuplot 2.0
  41.  * More efficient output Ian by Dall
  42.  */
  43. #include "object.h"                     /* from the TransFig distribution */
  44. #define FIG_DEFAULT (-1)
  45. #define FIG_ROMAN_FONT (0)
  46.  
  47. #ifndef FIG_RES
  48. /* Must be 80 for the Fig editor, but may be increased if used
  49.  * only by TransFig filters.
  50.  * Represents resolution per inch.
  51.  */
  52. #define FIG_RES         80
  53. #endif
  54.  
  55. #define FIG_COORD_SYS   2
  56.  
  57. #define FIG_MAGIC       "#FIG 1.4-TFX"
  58. #define FIG_HTIC        (5*FIG_RES/80)
  59. #define FIG_VTIC        (5*FIG_RES/80)
  60. #define FIG_FONT_S      FIG_DEFAULT
  61. #define FIG_HCHAR       (6*FIG_RES/80) /* Change if FIG_FONT_S is changed */
  62. #define FIG_VCHAR       (12*FIG_RES/80) /* Change if FIG_FONT_S is changed */
  63. #define FIG_ARROW_WIDTH FIG_HTIC
  64. #define FIG_ARROW_HEIGHT FIG_HTIC
  65.  
  66. static long FIG_xbase = FIG_RES/2;
  67. static long FIG_ybase = FIG_RES/2;
  68.  
  69. static long FIG_posx;
  70. static long FIG_posy;
  71. static int FIG_poly_vec_cnt;
  72. enum FIG_poly_stat {FIG_poly_new, FIG_poly_part};
  73. static enum FIG_poly_stat FIG_polyvec_stat;
  74. /* 5 inches wide by 3 inches high */
  75. #define FIG_XMAX (5 * FIG_RES)
  76. #define FIG_YMAX (3 * FIG_RES)
  77.  
  78. #define FIG_XOFF (FIG_RES/4)
  79. #define FIG_YOFF (FIG_RES/4)
  80.  
  81. static int FIG_type;            /* negative types use real lines */
  82. static float FIG_spacing;       /* length of dash or dot spacing */
  83. static int FIG_justify;         /* Fig justification T_*_JUSTIFIED */
  84. static float FIG_angle;         /* Fig text angle 0=horiz, Pi/2=vert */
  85.  
  86. #define FIG_POINT_TYPES POINT_TYPES /* we use the same points */
  87.  
  88. static
  89.   FIG_poly_clean(stat)
  90. enum FIG_poly_stat stat;
  91. {
  92.   if(stat == FIG_poly_part)
  93.         fprintf(outfile, " 9999 9999\n");
  94.   FIG_polyvec_stat = FIG_poly_new;
  95. }
  96.  
  97. FIG_init()
  98. {
  99.     FIG_posx = FIG_posy = 0;
  100.     FIG_polyvec_stat = FIG_poly_new;
  101.     FIG_linetype(-1);
  102.     FIG_justify_text(LEFT);
  103.     FIG_text_angle(0);
  104.  
  105.     fprintf(outfile, "%s\n", FIG_MAGIC);
  106.     fprintf(outfile, "%d %d\n", FIG_RES, FIG_COORD_SYS);
  107. }
  108.  
  109.  
  110. FIG_graphics()
  111. {
  112.     FIG_posx = FIG_posy = 0;
  113.     FIG_polyvec_stat = FIG_poly_new;
  114.     /* there is no way to have separate pictures in a FIG file */
  115. }
  116.  
  117.  
  118. FIG_text()
  119. {
  120.     /* there is no way to have separate pictures in a FIG file */
  121.     FIG_poly_clean(FIG_polyvec_stat);
  122.     FIG_posx = FIG_posy = 0;
  123.     fflush(outfile);
  124. }
  125.  
  126.  
  127. /* Line types for FIG work like this:
  128.  *  -2 : solid (border)
  129.  *  -1 : dashed 4 (axes)
  130.  *   0 : solid (first curve)
  131.  *   1 : dotted 3
  132.  *   2 : dashed 3
  133.  *   3 : dotted 6
  134.  *   4 : dashed 6
  135.  *   ... ...
  136.  */
  137.  
  138. FIG_linetype(linetype)
  139.         int linetype;                   /* expect linetype >= -2 */
  140. {
  141.     int last_FIG_type = FIG_type;
  142.     int last_FIG_spacing = FIG_spacing;
  143.     switch (linetype) {
  144.            case 0:
  145.            case -2: {
  146.                   FIG_type = 0; /* solid line */
  147.                   FIG_spacing = 0.0;
  148.                   break;
  149.            }
  150.            case -1: {
  151.                   FIG_type = 1; /* dashed */
  152.                   FIG_spacing = 4.0; /* dash length */
  153.                   break;
  154.            }
  155.            default: {
  156.                   linetype = abs(linetype); /* shouldn't be negative anyway */
  157.                   /* now linetype >= 1 */
  158.                   FIG_type = linetype % 2 + 1; /* dotted, dashed, ... */
  159.                   FIG_spacing = (linetype+1) / 2 * 3;
  160.                   break;
  161.            }
  162.     }
  163.     if (FIG_type != last_FIG_type || FIG_spacing != last_FIG_spacing)
  164.       FIG_poly_clean(FIG_polyvec_stat);
  165. }
  166.  
  167. FIG_move(x,y)
  168.         unsigned int x,y;
  169. {
  170.     int last_FIG_posx = FIG_posx;
  171.     int last_FIG_posy = FIG_posy;
  172.     FIG_posx = x;
  173.     FIG_posy = y;
  174.     if (FIG_posx != last_FIG_posx || FIG_posy != last_FIG_posy)
  175.           FIG_poly_clean(FIG_polyvec_stat);
  176. }
  177.  
  178.  
  179. FIG_vector(ux,uy)
  180.      unsigned int ux,uy;
  181. {
  182.   int x=ux, y=uy;
  183.  
  184.   if (FIG_polyvec_stat != FIG_poly_part)
  185.     {
  186.       fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  187.               O_POLYLINE, T_POLYLINE,
  188.               FIG_type, 1, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_spacing,
  189.               0, 0);
  190.       fprintf(outfile, "%d %d",
  191.               FIG_XOFF + FIG_posx, FIG_YMAX + FIG_YOFF - FIG_posy);
  192.       FIG_poly_vec_cnt = 1;
  193.       FIG_polyvec_stat = FIG_poly_part;
  194.     }
  195.   fprintf(outfile, " %d %d",
  196.           FIG_XOFF +  x, FIG_YMAX + FIG_YOFF-y);
  197.   FIG_poly_vec_cnt++;
  198.   if (FIG_poly_vec_cnt > 50)
  199.     FIG_poly_clean(FIG_polyvec_stat);
  200.  
  201.   FIG_posx = x;
  202.   FIG_posy = y;
  203. }
  204.  
  205.  
  206. FIG_arrow(sx, sy, ex, ey, head)
  207.         int sx, sy;     /* start coord */
  208.         int ex, ey;     /* end coord */
  209.     BOOLEAN head;
  210. {
  211.     FIG_poly_clean(FIG_polyvec_stat);
  212.         fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  213.                 O_POLYLINE, T_POLYLINE,
  214.                 FIG_type, 1, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_spacing,
  215.                 head ? 1 : 0, 0);
  216.         /* arrow line */
  217.     if ( head )
  218.             fprintf(outfile, "%d %d %.3f %.3f %.3f\n",
  219.                     0, 0, 1.0,
  220.             (double)FIG_ARROW_WIDTH, (double)FIG_ARROW_HEIGHT);
  221.         fprintf(outfile, "%d %d %d %d 9999 9999\n",
  222.                 FIG_XOFF + sx, FIG_YOFF + FIG_YMAX - sy,
  223.         FIG_XOFF + ex, FIG_YOFF + FIG_YMAX - ey);
  224.  
  225.         FIG_posx = ex;
  226.         FIG_posy = ey;
  227. }
  228.  
  229.  
  230. FIG_put_text(x, y, str)
  231.         int x, y;
  232.         char *str;
  233. {
  234.   if (strlen(str) == 0) return;
  235.   FIG_poly_clean(FIG_polyvec_stat);
  236.     y = y - FIG_VCHAR/2;                /* assuming vertical center justified */
  237.  
  238.     fprintf(outfile, "%d %d %d %d %d %d %d %6.3f %d %d %d %d %d %s\01\n",
  239.                   O_TEXT, FIG_justify,
  240.                   FIG_ROMAN_FONT, FIG_FONT_S, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_angle,
  241.                   FIG_DEFAULT, FIG_VCHAR, FIG_HCHAR*strlen(str), FIG_XOFF + x,
  242.         FIG_YMAX + FIG_YOFF-y, str);
  243. }
  244.  
  245. int FIG_justify_text(mode)
  246.         enum JUSTIFY mode;
  247. {
  248.     switch(mode) {
  249.            case LEFT: FIG_justify = T_LEFT_JUSTIFIED; break;
  250.            case CENTRE: FIG_justify = T_CENTER_JUSTIFIED; break;
  251.            case RIGHT: FIG_justify = T_RIGHT_JUSTIFIED; break;
  252.            /* shouldn't happen */
  253.            default: FIG_justify = T_LEFT_JUSTIFIED; break;
  254.     }
  255.     return (TRUE);
  256. }
  257.  
  258. int FIG_text_angle(angle)
  259.         int angle;
  260. {
  261.     if (angle)
  262.          FIG_angle = Pi / 2.0;  /* vertical is pi/2 radians */
  263.     else
  264.          FIG_angle = 0.0;               /* horizontal */
  265.     return (TRUE);
  266. }
  267.  
  268. FIG_reset()
  269. {
  270.     FIG_poly_clean(FIG_polyvec_stat);
  271.     FIG_posx = FIG_posy = 0;
  272.     fflush(outfile);
  273. }
  274.  
  275. #ifdef MSDOS
  276. #undef long
  277. #endif /* MSDOS */
  278.